home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11211 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.8 KB

  1. Path: lrz-muenchen.de!news
  2. From: watzka@stat.uni-muenchen.de (Kurt Watzka)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Pointers to register
  5. Date: 22 Mar 1996 10:33:31 GMT
  6. Organization: Leibniz-Rechenzentrum, Muenchen (Germany)
  7. Distribution: world
  8. Message-ID: <4itvlr$5mi@sparcserver.lrz-muenchen.de>
  9. References: <1239@altheim.win-uk.net><18MAR199607594276@erich.triumf.ca> <1242@altheim.win-uk.net><314EC8E6.216E@ix.netcom.com> <1245@altheim.win-uk.net>
  10. NNTP-Posting-Host: sun2.lrz-muenchen.de
  11.  
  12. broldham@altheim.win-uk.net (Brian R. Oldham) writes:
  13.  
  14. >You are quite right.  I checked in dos.h (BYTEREGS) and al, ah etc. are
  15. >all unsigned char. So today I went back to my program and changed the
  16. >declaration of scancode from pointer to int to a pointer to unsigned
  17. >char. Sure enough, my program compiled without complaint, but - guess
  18. >what - when I ran it in a main() the bloody system froze.
  19.  
  20. >So back to my original question: why does the ostensibly incorrect
  21. >declaration:
  22.  
  23. >    *ptr = union_member_var;
  24.  
  25. 1) This is not a declaration, and it is not an incorrect statement, because
  26.    *ptr (in your case) is an int, and you _can_ assign an unsigned char 
  27.    to an int if an int can hold all possible values of an unsigned char.
  28.    In this case, the result is well defined.
  29.  
  30. >work, and the correct:
  31.  
  32. >    ptr = &union_member_var;
  33.  
  34. If ptr is a pointer to int, and union_member_var is an unsigned char, this
  35. statement is _not_ correct, and if I remember right, someone told you
  36. that already.
  37.  
  38. Why do you think that it is more correct to assign a pointer to an 
  39. unsigned char to a variable that holds a pointer to an int than to
  40. assign an unsigned char to a variable that is an int.
  41.  
  42. Kurt
  43. --
  44. | Kurt Watzka                             Phone : +49-89-2180-6254
  45. | watzka@stat.uni-muenchen.de
  46. | ua302aa@sunmail.lrz-muenchen.de
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.